#include "version.h"
#include <stdio.h>
#include <string.h>

char* CVersionManagement::versionString = NULL;
char *CVersionManagement::buildTimeString = NULL;

char* CVersionManagement::getVersionString(void)
{
	if (CVersionManagement::versionString==NULL)
	{
		char version[1024];
		sprintf(version,"-= Project Axium Version: %s.%s.%s", _VERSION_MAJOR, _VERSION_MINOR, _VERSION_UPDATE);
		#ifdef _RELEASE_TO_PUBLIC
		sprintf(version,"%s - Official release",version);
		#else
		sprintf(version,"%s - SVN build (Revision: %d%s)", version, _VERSION_SVN, (_VERSION_SVN_MODIFIED==1)?" [modified]":"");
		#endif
		sprintf(version,"%s =-", version);

		CVersionManagement::versionString = new char[strlen(version)+1];
		sprintf(CVersionManagement::versionString,"%s",version);
	}
	return CVersionManagement::versionString;
}

char* CVersionManagement::getBuildTimeString(void)
{
	if (CVersionManagement::buildTimeString==NULL)
	{
		char buildTime[1024];
		
		int timezone = 0;
		char timestring[256];

		sprintf(&timestring[0],"%s",__TIMESTRING__);
		char* offset=&timestring[0];

		for (int run=0;run<3;run++)
		{
			if (offset!=NULL)
				offset=strchr(&offset[1],' ');
		}
		if (offset!=NULL)
		{
			offset[6]='\0';
			sscanf(offset,"%d",&timezone);
		}
		sprintf(buildTime,"Build date: %s - Build time: %s UTC %s%.4d",__COMPILEDATE__,__COMPILETIME__,timezone>=0?"+":"",timezone);

		CVersionManagement::buildTimeString = new char[strlen(buildTime)+1];
		sprintf(CVersionManagement::buildTimeString,"%s",buildTime);
	}
	return CVersionManagement::buildTimeString;
}